import WidgetCell from '../widget.cell';
import { NbObjectWidgetScheme } from './scheme';

export default function NbObjectWidget(props: NbObjectWidgetScheme) {
  const { properties, name } = props;

  return (
    <>
      {Object.entries(properties)
        .sort(([key1, value1], [key2, value2]) => value1.order! - value2.order!)
        .map(([key, value]) => {
          const namePath: string[] = name ? [...name, key] : [key];
          return <WidgetCell key={key} name={namePath} {...value} />;
        })}
    </>
  );
}
